package com.yc.project1;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.*;

/**
 * @author zwei
 * @create 2024-07-31 19:05
 */
@Configuration
@ComponentScan
@PropertySource("db.properties")        //利用@PropertySource注解加载mysql数据库配置文件
@EnableAspectJAutoProxy
public class AppConfig {
    @Value("${name}")
    private String username;
    @Value("${pwd}")
    private String password;
    @Value("${driver}")
    private String driverClassName;
    @Value("${url}")
    private String url;


    @Bean(initMethod = "init")
    public DruidDataSource druidDataSource() {              //利用bean类创建第三方类的对象
        DruidDataSource ds = new DruidDataSource();
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setDriverClassName(driverClassName);
        ds.setUrl(url);
        ds.setInitialSize(5);
        ds.setMinIdle(5);
        ds.setMaxActive(20);
        return ds;
    }
}
